let { ajax , $ } = Utils;

class RenderNewbook{
      constructor() {
            this.init();
      }
      async init(){
            this.list_wrapper = $(".newSquare-box-con");
            // this.pageNo = 1;
            // this.showNo = 5;
            // 1. 以数据加载开始;
            // 2. 事件委托;
            this.res = await this.loadData();
            console.log(res);
            this.render();
      }     
      // 加载数据;
      async loadData(){
            let url  = "http://localhost/xs";
            let data = {
                 moduleld :11
            }     
            // await 
            let res = await ajax( url , { data : data , dataType : "json" });
            // console.log(res);
            return res;
      }
      // 渲染页面;
      render(){
            let data = this.res.data.data.itemInfo;
            // 处理data;
            data = this.interceptData(data);
            let template = `
                        <%  for(var i = 0 , item ; item = data[i]; i++) {%>
                            <div class="item">
                            <div class="item-img">
                                <div class="item-img-bg"> <a href="#"
                                        target="_blank"><img src="<%= item.bgImgUrl%>"
                                             alt="" title=""
                                            ></a>
                                 </div>
                                
                            </div>
                            <div class="item-con">
                            <div class="item-con-title"><a href="#"
                                    target="_blank"><%= item.itemName%></a></div>
                            <div class="item-con-dis"><%= item.importantDesc%></div>
                            <div class="tag">
                                 <span><%= item.tagList[0]%><div class="jiao">
                                        <div class="jiao-inner"></div>
                                    </div>
                                </span> 
                                <span><%= item.tagList[1]%><div class="jiao">
                                        <div class="jiao-inner"></div>
                                    </div></span> <span><%= item.tagList[2]%><div class="jiao">
                                        <div class="jiao-inner"></div>
                                    </div></span> <span><%= item.tagList[3]%><div class="jiao">
                                        <div class="jiao-inner"></div>
                                    </div></span>
                             </div>
                            <div class="item-bottom clearfix">
                                <div class="f_left"><span>￥</span><%= item.price%><i>包邮</i>
                                </div>
                                <div class="f_right btn-status">
                                 
                                    <div class="btn">立即抢购</div>
                                </div>
                            </div>
                        </div>
                        <% } %>
                              `;
            var html = ejs.render(template , {data : data})
            console.log(html);
            this.list_wrapper.innerHTML = html;
      }
      //裁剪数据的;
      interceptData(data){
            // 裁剪;
            return data;
      }
    
}

new RenderNewbook();